using Common.Commands;
using Common.Commands.AccountCommands;
using Core.Domain.Model;
using Sanelib.DataOperation;
using Sanelib.Dto;

namespace Core.Processors.AccountProcessors
{
    public class UpdateAccountProcessor : ICommandProcessor<UpdateAccount>
    {
        private readonly IRepository<Account> _accountRepository;

        public UpdateAccountProcessor(IRepository<Account> accountRepository)
        {
            _accountRepository = accountRepository;
        }

        public dynamic Process(UpdateAccount command)
        {
            var response = new WebApiResultResponse();

            var account = _accountRepository.GetById(command.Id);

            account.Name = command.Name;
            account.AccountType = command.AccountType;
            account.AccountNumber = command.AccountNumber;
            account.Industry = command.Industry;
            account.BillingStreet = command.BillingStreet;
            account.BillingCity = command.BillingCity;
            account.BillingState = command.BillingState;
            account.BillingPostalCode = command.BillingPostalCode;
            account.BillingCountry = command.BillingCountry;
            account.BillingLatitude = 0;
            account.BillingLongitude = 0;
            account.ShippingStreet = command.ShippingStreet;
            account.ShippingCity = command.ShippingCity;
            account.ShippingState = command.ShippingState;
            account.ShippingPostalCode = command.ShippingPostalCode;
            account.ShippingCountry = command.ShippingCountry;
            account.ShippingLatitude = 0;
            account.ShippingLongitude = 0;
            account.Phone = command.Phone;
            account.Mobile = command.Mobile;
            account.Fax = command.Fax;
            account.Website = command.Website;
            account.Email = command.Email;
            account.Description = command.Description;
            account.ImageData = command.ImageData;
            account.ModifiedBy = command.UserId;

            _accountRepository.Update(account);

            response.IsSuccess = true;

            return response;
        }
    }
}
